<?php

class Categorie_Modele extends Modele
{
	private $_id;
	private $_name;
	private $_isPublic;
	private $_color;

	static public function getRef($id, $name, $isPublic, $color)
	{
		return new Categorie_Modele($id, $name, $isPublic, $color);
	}	
	
	
	public function Categorie_Modele($id, $name, $isPublic, $color)
	{
		parent::Modele("categorie","id");
		$this->_id = $id;
		$this->_name = $name;
		$this->_isPublic = $isPublic;
		$this->_color = $color;
	}
	
	public function get_id()
	{
		return $this->_id;
	}
	
	public function get_name()
	{
		return $this->_name;
	}
	
	public function get_isPublic()
	{
		return $this->_isPublic;
	}
	
	public function get_colorId()
	{
		return $this->_color;
	}

	public function get_nb_article()
	{
		$adapt = new SQLAdapt();
		$req = "select count(*) from article where categorieId = ".$this->_id." and isPublished = 1";
		$res = $adapt->query($req);
		if($res != null)
		{
			$res = $res->fetch();
			return $res[0];
		}
		return 0;
	}
	
	public function get_color_name()
	{
		$adapt = new SQLAdapt();
		$req = "select name from color where id = ".$this->_color;
		$res = $adapt->query($req);
		$res = $res->fetch();
		return $res[0];
	}
}

?>
